<template>
  <div class="container">
    <el-dialog title="新增目录" :visible.sync="visible" width="20%" close="close" :close-on-click-modal="false" :show-close="false">
      <el-form :model="addForm" :rules="rules" ref="ruleFormRefs" label-width="80px">
        <el-form-item label="所属学科">
          <el-select v-model="addForm.subjectID" placeholder="请选择">
            <el-option v-for="item in subjectList" :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="目录名称" prop="tagName">
          <el-input v-model="addForm.tagName" placeholder="请选择目录名称"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="handleEdit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { add } from '@/api/hmmm/tags'

export default {
  name: 'TagsAdd',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    subjectList: {
      type: Array,
      required: true
    }
  },
  components: {},
  data () {
    return {
      isShow: false,
      addForm: {
        subjectID: '',
        tagName: ''
      },
      rules: {
        tagName: [
          { required: true, message: '请输入名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  watch: {},
  created () {
  },
  mounted () {
  },
  computed: {
  },
  methods: {
    close () {
      this.$refs.ruleFormRefs.resetFields()
      this.$emit('update:visible', false)
    },
    async handleEdit () {
      this.$emit('update:visible', false)
      // console.log(this.subjectList)
      // console.log(this.addForm)
      const res = await add(this.addForm)
      // console.log(res)
      if (res.status !== 200) return this.$message.warning('添加失败!')
      this.$message.success('添加成功!')
      this.$emit('refresh')
    }
  }
}
</script>

<style lang="less" scoped>
</style>
